//
//  HttpRequestManager.m
//  DesighBook
//
//  Created by 梅明 on 15/9/14.
//  Copyright (c) 2015年 梅明. All rights reserved.
//

#import "HttpRequestManager.h"
#import "AFNetworking.h"
#import "NetInterface.h"

@implementation HttpRequestManager

+(instancetype)shareInstnce
{
    static HttpRequestManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,^{
        manager = [[HttpRequestManager alloc]init];
    });
    return manager;
}

//第一个页面
-(void)getMainInfoSuccess:(httpSuccess)success AndFailure:(httpFailure)Failure
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:Main_url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        NSLog(@"%@",responseObject);
        NSDictionary *dic = responseObject[@"data"];
        
        success(dic);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        Failure(error);
    }];
}

//主页面的cell详情请求
-(void)getmaintableInfoWithID:(NSString *)numberId AndSuccess:(httpSuccess)success AndFailure:(httpFailure)Failure
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString *str = [NSString stringWithFormat:Maincell_url,numberId];
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        success(responseObject[@"data"]);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        Failure(error);
        
    }];
}

//第二个页面
//-(void)getSecondInfoSuccess:(httpSuccess)success AndFailure:(httpFailure)Failure
//{
//    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
//    [manager GET:Seceond_url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        NSArray *arr = responseObject[@"data"];
//        success(arr);
//        
//        
//    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        Failure(error);
//    }];
//}

//第二个页面家装信息请求
-(void)getSecondInfoPage:(int)page AndSpace:(NSInteger)space AndStyle:(NSInteger)style Success:(httpSuccess)success AndFailure:(httpFailure)Failure
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString *urlStr = [NSString stringWithFormat:Seceondone_url,page,space,style];
   
//    NSLog(@"url ==== %@",urlStr);
    [manager GET:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSArray *arr = responseObject[@"data"];
        success(arr);
//        NSLog(@"response == %@",responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error == %@",error);
        Failure(error);
        
    }];
    
    
}

//第二个页面工装信息请求
-(void)getSecondInfoPage:(int)page AndSpace:(NSInteger)space Success:(httpSuccess)success AndFailure:(httpFailure)Failure
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString *urlStr = [NSString stringWithFormat:Secondtwo_url,page,space];
    [manager GET:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSArray *arr = responseObject[@"data"];
        success(arr);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        Failure(error);
        
        
    }];
}



//第二个scrollview的详情
-(void)getSecondScrollviewInfoPageId:(NSString *)pageid AndSuccess:(httpSuccess)success AndFailure:(httpFailure)Failure
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString *str = [NSString stringWithFormat:secondScrollview_url,pageid];
//    NSLog(@"%@",str);
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        NSLog(@"response == %@",responseObject);
        success(responseObject[@"data"]);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        Failure(error);
    }];
}

//第二个scrollview的跳转detail页面
-(void)getInfoWithNumberId:(NSString *)numberid AndSuccess:(httpSuccess)success AndFailure:(httpFailure)Failure
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString *str = [NSString stringWithFormat:seconsrolldetail_url,numberid];
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        NSLog(@"%@",responseObject);
        success(responseObject[@"data"]);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        Failure(error);
        
    }];
}


//第三个问答页面
-(void)getAskInfoWithurl:(NSString *)url AndSuccess:(httpSuccess)success AndFailure:(httpFailure)Failure
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        NSLog(@"responseObject  == %@",responseObject);
        success(responseObject[@"data"]);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        Failure(error);
        
        
    }];
}

//第三个问答页面的点击详情
-(void)getAskDetailInfoWithid:(NSString *)numberid AndSuccess:(httpSuccess)success AndFailure:(httpFailure)Failure
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString *str = [NSString stringWithFormat:AskDetail_url,numberid];
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        success(responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        Failure(error);
        
    }];
    
}


@end
